package com.yamanyar.weebill.view;

import java.io.Serializable;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.yamanyar.weebill.domain.Component;
import com.yamanyar.weebill.service.ComponentService;

/**
 * Creates a Component. Created in Jun 28, 2008.
 * 
 * @author Kaan Yamanyar
 */
@org.springframework.stereotype.Component("createComponent")
@Scope("request")
public class CreateComponent implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6785907946599065081L;

	private ComponentService componentService;

	private Component component = new Component();

	@Autowired
	public CreateComponent(ComponentService componentService) {
		this.componentService = componentService;
	}

	public Component getComponent() {
		return component;
	}

	public void setComponent(Component component) {
		this.component = component;
	}

	public String save() {
		componentService.createNew(component);
		FacesMessage facesMessage = new FacesMessage(
				FacesMessage.SEVERITY_INFO, "Component is saved successfully",
				"OK");
		FacesContext.getCurrentInstance().addMessage(null, facesMessage);
		component = new Component();
		return null;
	}
}
